/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.dataset.netsensor;

import java.sql.Timestamp;

import nfse.NetFSEUtil;
import nfse.dataset.session.Session;


public class NetSensorSession extends Session {

	// A Net/Sensor record is identified by a triple of (sensor, strideID,
	// sensorID)

	public long recID = -1;

	public long strideID = -1;

	public String appProto = "";

	public double duration = -1.0;

	public int state = 0;

	public String stateStr = "";

	public String flags = "";

	public String tag = "";

	public String getDisplayTypeName() {
		return "Flows";
	}

	public String toString() {
	    StringBuilder temp = new StringBuilder();
		long millis = this.getStartTS().getTime();
		temp.append(millis / 1000 + ".");
		temp.append(millis % 1000 + " ");
		if (duration == -1.0) {
			temp.append("? ");
		} else {
			temp.append(duration + " ");
		}
		temp.append(this.getSrcAddr());
		temp.append(" ");
		temp.append(this.dstAddr);
		temp.append(" ");
		temp.append(this.appProto);
		temp.append(" ");
		temp.append(this.srcPort + " ");
		temp.append(this.dstPort + " ");
		temp.append(NetFSEUtil.getProtocolName(this.proto));
		temp.append(" ");
		if (srcBytes == -1) {
			temp.append("? ");
		} else {
			temp.append(srcBytes + " ");
		}
		if (dstBytes == -1) {
			temp.append("? ");
		} else {
			temp.append(dstBytes + " ");
		}
		temp.append(state);
		temp.append(" ");
		temp.append(flags);
		if (tag.length() > 0) {
			temp.append(" ");
			temp.append(tag);
		}

		return temp.toString();
	}

	public Timestamp getEndTS() {
		return this.stopTS;
	}

	public boolean isInit() {
		if (srcBytes == -1 && dstBytes == -1)
			return true;
		return false;
	}

}
